﻿using UnityEngine;

namespace UI
{
    public class HeroInfoPage : Page
    {
        #region Top label
        public UILabel heroNameText;
        public UILabel heroNameProportyText;
        public UILabel heroAptitudeText;
        public UILabel heroQualityText;
        public UILabel heroSpaceText;
        public UITexture hero2DTexture;
        #endregion
        //描述
        public UILabel heroDescribeText;
        public UITexture spaceBg;
        //public GameObject[] spaceBgs;
        #region UIHero
        public UIHero hero;
        #endregion

        protected override void DoOpen()
        {
            base.DoOpen();
            GetComponent<PageTweener>().Play();
        }
        public void SetHero(string id)
        {
            hero = new UIHero(id);
            FillTopData();
            string str = TableTextBlo.GetText(hero.heroData.desc);
            heroDescribeText.text = "　　" + str;
            SetHeroSpace(hero.heroData.space);
            UIRoot root = UIAutoSize.Instance.root;
            Dict.Dao.TableHeroInfoDao thi = Dict.DictDataManager.Instance.tableHeroInfoDao;
            foreach(var item in thi.CacheList)
            {
                if(item.id == id)
                {
                    hero2DTexture.width = item.width;
                    hero2DTexture.height = item.height;
                    hero2DTexture.transform.localPosition = new Vector3(item.x_left - root.manualWidth / 2, root.activeHeight / 2 - item.y_top, 0);
                    break;
                }
            }
        }

        void SetHeroSpace(int space)
        {
            switch(space)
            {
                case 1:
                    spaceBg.mainTexture = AssetLoad.ResourceManager.Instance.LoadResource("TujianBg/UI_tujian_beijing_SAO") as Texture2D;
                    break;
                case 2:
                    spaceBg.mainTexture = AssetLoad.ResourceManager.Instance.LoadResource("TujianBg/UI_tujian_beijing_ALO") as Texture2D;
                    break;
                case 3:
                    spaceBg.mainTexture = AssetLoad.ResourceManager.Instance.LoadResource("TujianBg/UI_tujian_beijing_GGO") as Texture2D;
                    break;
            }
            //for(int i = 0;i< spaceBgs.Length; i++)
            //{
            //    spaceBgs[i].SetActive(false);
            //}
            //spaceBgs[space - 1].SetActive(true);
        }

        public void FillTopData()
        {
            heroNameText.text = CommonMethod.GetHeroName(hero.heroId);
            string strIcon = hero.heroData.iconName.Replace("icon", "card");
            AssetLoadHelper.Instance.SetTextureAsync(hero2DTexture, "heroPainter/" + strIcon, false);
            heroNameProportyText.text = hero.talentLevel != 0 ? "+" + hero.talentLevel + "" : "";
            heroAptitudeText.text = hero.heroData.quality + "";
            heroQualityText.text = "[" + FontColor.Get(hero.heroData.quality) + "]" + TableTextBlo.GetText("quality_name_" + hero.heroData.quality) + "[-]";
            heroSpaceText.text = "" + hero.GetHeroSpaceName() + "";
        }
    }
}
